#pragma once

#include<process.h>
#include<Windows.h>

class Timer
{
public:
	friend void TimerThreadFunction(void* arguments);
	//--
	Timer()
		:_timesUp(false),
		_timeLimitInMilliseconds(40),
		_id(-1)
	{
	}
	void Start(const int& timeLimitInMilliseconds)
	{
		_timesUp = false;
		_timeLimitInMilliseconds = timeLimitInMilliseconds;
		_id = _beginthread(TimerThreadFunction , 0 , (void*)this);
	}
	inline bool TimeIsUp() const
	{
		return _timesUp;
	}
private:
	bool _timesUp;
	int _timeLimitInMilliseconds;
	int _id;
};

void TimerThreadFunction(void* Pointer)
{
	Timer* timerPointer = (Timer*)Pointer;
	const int myID = timerPointer->_id;
	Sleep(timerPointer->_timeLimitInMilliseconds);
	if(myID == timerPointer->_id)
	{
		timerPointer->_timesUp = true;
	}
}